#include "stdafx.h"
#include "Configurator.h"

#include <fstream>
#include <stdlib.h>

const std::string BitCountSTR = "BinCount";
const std::string VectorTypeSTR = "VectorType";
const std::string MetricTypeSTR = "MetricType";

diploma::Configurator::Configurator(const std::string& path)
{
	ParseFile(path);
}

int diploma::Configurator::GetBinCount()
{
	return data_[BitCountSTR];
}

diploma::VectorType diploma::Configurator::GetVectorType()
{
	return (diploma::VectorType)data_[VectorTypeSTR];
}

diploma::MetricType diploma::Configurator::GetMetricType()
{
	return (diploma::MetricType)data_[MetricTypeSTR];
}

void diploma::Configurator::ParseFile(const std::string& path)
{
	const int lineSize = 1024;
	char line[lineSize];

	std::ifstream fileToParse(path.c_str());

	while (!fileToParse.eof())
	{
		fileToParse.getline(line, lineSize);
		std::string allLine(line);
		std::string name(allLine.begin(), allLine.begin() + allLine.find(' '));
		std::string val(allLine.begin() + allLine.find(' ') + 1, allLine.end());
		data_[name] = atoi(val.c_str());
	}
}